export default {
  methods: {
    // 点赞
    likeHandler(e) {
      const { videoitem } = e.currentTarget.dataset;
      const currentVideo = this.allVideoData.find(
        (i) => i.eid === videoitem.eid
      );

      currentVideo.likeActive = !currentVideo.likeActive;

      if (currentVideo.likeActive) {
        currentVideo.episodesLikes = formatNumberToK(
          currentVideo.episodes_likes + 1
        );
      } else {
        currentVideo.episodesLikes = formatNumberToK(
          currentVideo.episodes_likes
        );
      }

      this.allVideoData = [...this.allVideoData];
      this.videoSwiper.updateCurrentVideo();
    },

    // 收藏
    async starHandler(e) {
      const { videoitem } = e.currentTarget.dataset;
      const currentVideo = this.allVideoData.find(
        (i) => i.eid === videoitem.eid
      );
      const { currentAblum } = this;

      currentVideo.starActive = !currentVideo.starActive;

      try {
        const getStorageSyncRes = uni.getStorageSync("likeAblum");
        if (currentVideo.starActive) {
          currentVideo.episodesChasing = formatNumberToK(
            currentVideo.episodes_chasing + 1
          );
          const newData = getStorageSyncRes
            ? [...getStorageSyncRes, currentAblum]
            : [currentAblum];
          uni.setStorageSync("likeAblum", newData);
        } else {
          currentVideo.episodesChasing = formatNumberToK(
            currentVideo.episodes_chasing
          );
          const newData = getStorageSyncRes.filter(
            (i) => i.ablum_id !== currentAblum.ablum_id
          );
          uni.setStorageSync("likeAblum", newData);
        }
      } catch (e) {
        console.error("Storage operation failed:", e);
      }

      this.allVideoData = [...this.allVideoData];
      this.videoSwiper.updateCurrentVideo();
    },

    // 分享
    shareVideo(e) {
      const { videoitem } = e.currentTarget.dataset;
      const currentVideo = this.allVideoData.find(
        (i) => i.eid === videoitem.eid
      );
      currentVideo.episodesShares = formatNumberToK(
        currentVideo.episodes_shares + 1
      );
      this.allVideoData = [...this.allVideoData];
      this.videoSwiper.updateCurrentVideo();
    },

    // 选集
    onChangeEpisode(e) {
      const { episodeitem } = e;
      let episode = episodeitem.episodes_num - 1;
      this.videoSwiper.setStart(episode);
      this.showChangeVideoPopup = false;
    },
  }
}